<?php
namespace app\index\controller;
use think\Controller;

class Domain extends Controller{
    //
    public function index($page = ''){
        $domain = $this->request->host();
        $dmArr = \app\index\model\Domain::instance()->get($domain);
        if($dmArr['unvisit'] == '1'){
            return $this->fetch('error/404', ['msg' => '页面禁止访问']);
        }
        if($dmArr){
            $dmArr['tname'] = trim($dmArr['tname']);
            if($dmArr['bind'] == 1 && $dmArr['tname'] != ''){
                return controller('index/AdvertPage')->index($dmArr['tname'], '');
            }
        }else{
            $dmArr['tdno'] = 'deny';
        }
        $dmArr['path'] = '/tpl/dm/'.$dmArr['tdno'];
        $dmArr['url'] = '/page';
        $ext = $this->request->ext();
        $file = $page ? '.'.$dmArr['path'].'/'.$page.'.'.$ext : '.'.$dmArr['path'].'/index.html';
        if(!file_exists($file)){
            $this->error('模板文件找不到，请确认模板文件是否已经上传？');
        }
        return $this->fetch($file, ['tpl' => $dmArr]);
    }
}